/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using VSLangProj;
using VSLangProj80;
using Microsoft.VisualStudio.VCProjectEngine;

namespace DaveSexton.DocProject
{
	public class VCSourceProject : MarshalByRefObject, ISourceProject
	{
		#region Public Properties
		public string Name
		{
			get
			{
				return project.Name;
			}
		}

		public virtual IProjectOutput Output
		{
			get
			{
				if (output == null)
					output = CreateOutput();

				return output;
			}
		}

		public object Project
		{
			get
			{
				return project;
			}
		}

		[CLSCompliant(false)]
		public VCProject VCProject
		{
			get
			{
				return project;
			}
		}
		#endregion

		#region Private / Protected
		private readonly VCProject project;
		private IProjectOutput output;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="VCSourceProject" /> class.
		/// </summary>
		internal VCSourceProject(VCProject project)
		{
			if (project == null)
				throw new ArgumentNullException("project");

			this.project = project;
		}
		#endregion

		#region Methods
		[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.LinkDemand,
		Flags = System.Security.Permissions.SecurityPermissionFlag.Infrastructure)]
		public override object InitializeLifetimeService()
		{
			return null;
		}

		protected virtual IProjectOutput CreateOutput()
		{
			return new VCProjectOutput(this);
		}
		#endregion

		#region IComparableProject Members
		public bool Matches(object other)
		{
			VCSourceProject otherProject = other as VCSourceProject;

			return otherProject != null && project.ProjectFile.Equals(otherProject.project.ProjectFile, StringComparison.OrdinalIgnoreCase);
		}

		public int GetMatchCode()
		{
			return project.ProjectFile.GetHashCode();
		}
		#endregion
	}
}
